package com.pointi.sysChecker ;

import java.io.File ;

import javax.xml.parsers.DocumentBuilder ;
import javax.xml.parsers.DocumentBuilderFactory ;

import org.w3c.dom.Document ;
import org.w3c.dom.Element ;
import org.w3c.dom.Node ;
import org.w3c.dom.NodeList ;

public class sysConfig
{
	// DATABASE
	public String s_file_path = "" ;

	public sysConfig() {}

	public void InitializeData()
	{
		// DATABASE
		s_file_path = "" ;
	}

	public Document ReadConfXML(String strFile, sysConfig conf_data) throws Exception
	{
		NodeList mCATEGORY = null ;
		Node mNode = null ;
		conf_data.InitializeData() ;
		try
		{
			File file = new File(strFile) ;
			DocumentBuilderFactory docBuildFact = DocumentBuilderFactory.newInstance() ;
			DocumentBuilder docBuild = docBuildFact.newDocumentBuilder() ;
			Document doc = docBuild.parse(file) ;
			doc.getDocumentElement().normalize() ;
			if (doc.getDocumentElement().getNodeName().equals("configuration"))
			{
				// CONF | CATEGORY | DATABASE
				mCATEGORY = doc.getElementsByTagName("syschecker") ;
				mNode = mCATEGORY.item(0) ;
				if (mNode.getNodeType() == Node.ELEMENT_NODE)
				{
					Element mElmnt = (Element) mNode ; // TYPE_CAST
					conf_data.s_file_path = fnReadTerminal(mElmnt, "filepath") ;
				}
			}
			return doc ;
		} catch (Exception e) { e.printStackTrace() ; }
		return null ;
	}
	
	protected String fnReadTerminal(Element inElmnt, String inTagName)
	{
		NodeList mList= inElmnt.getElementsByTagName(inTagName) ;
		Element mElmnt = (Element) mList.item(0) ;
		Node mNode = mElmnt.getFirstChild() ;
		return mNode.getNodeValue() ;
	}

	public void WriteLogConfigurationData(sysConfig conf_data)
	{
		System.out.println("---------- System Resource Checker ----------") ;
		System.out.println("filepath	: " + conf_data.s_file_path) ;
		System.out.println("---------------------------------------------") ;
	}
}